#include <stdio.h>
#include <winsock2.h>

int main() {
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
        fprintf(stderr, "WSAStartup failed\n");
        return 1;
    }

    SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == INVALID_SOCKET) {
        fprintf(stderr, "socket creation failed\n");
        WSACleanup();
        return 1;
    }

    WSAEVENT event = WSACreateEvent();
    if (event == WSA_INVALID_EVENT) {
        fprintf(stderr, "WSACreateEvent failed\n");
        closesocket(sock);
        WSACleanup();
        return 1;
    }

    if (WSAEventSelect(sock, event, FD_READ) != 0) {
        fprintf(stderr, "WSAEventSelect failed\n");
        WSACloseEvent(event);
        closesocket(sock);
        WSACleanup();
        return 1;
    }

    int result = WSAWaitForMultipleEvents(1, &event, FALSE, 5000, FALSE);

    if (result == WSA_WAIT_FAILED) {
        fprintf(stderr, "WSAWaitForMultipleEvents failed\n");
    } else if (result == WSA_WAIT_TIMEOUT) {
        printf("Timeout\n");
    } else if (result == WSA_WAIT_EVENT_0) {
        printf("Data is available to read from stdin\n");
    }

    WSACloseEvent(event);
    closesocket(sock);
    WSACleanup();

    return 0;
}
